package com.topNews.base.service.record.impl;

import java.util.List;

import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.Restrictions;

import com.topNews.base.constant.Constants;
import com.topNews.base.dao.ActionRecordDAO;
import com.topNews.base.service.record.ActionRecordService;
import com.topNews.entity.ActionRecord;

public class ActionRecordServiceImpl implements ActionRecordService {
	private ActionRecordDAO actionRecordDAO;

	public void setActionRecordDAO(ActionRecordDAO actionRecordDAO) {
		this.actionRecordDAO = actionRecordDAO;
	}


	@Override
	public void addActionRecord(ActionRecord actionRecord) {
		actionRecord.setUpdatePeopleID(0L);
		actionRecord.setUpdatePeopleName(Constants.DEFAULTPEOPLENAME);
		actionRecord.setArAction(Constants.DEFAULTACTION);
		actionRecordDAO.save(actionRecord);
	}


	@Override
	public List<ActionRecord> searchActionRecord() {
		DetachedCriteria criteria = DetachedCriteria.forClass(ActionRecord.class);
		criteria.addOrder(Order.desc("actionRecordID"));
		return actionRecordDAO.findByCriteria(criteria, Constants.ACTIONRECORDSIZE);
	}


	@Override
	public String searchActionRecordRemark() {
		DetachedCriteria criteria = DetachedCriteria.forClass(ActionRecord.class);
		
		criteria.addOrder(Order.desc("actionRecordID"));
		criteria.add(Restrictions.eq("arType", 1L));
		
		List<ActionRecord> arlist=actionRecordDAO.findByCriteria(criteria,1);
		
		return arlist.size()<=0?"blue":arlist.get(0).getArRemark();
	}
	
}
